{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Wk2Peds"

// By ArtemQa146

// 0@ ped - 10@ render, 11@ render

const
    Peds_Find = 29@
    Ped_Skin = 1@
    Ped_Select = 28@
    Bit_sets = 31@
    Select_Hand = 1
    Number_Peds = 4
    Progress = 30@
    Drink_or_eat = 27@
    iBuffer = 26@
    Pause_Time = 400
    Pause = 1000
end

0085: iBuffer = 0@ // (int)
0@ = -1

while true
wait 50
if
    Player.Defined($PLAYER_CHAR)
then
gosub @Ped_20
gosub @Realese_animation
    if
        not $ACTIVE_INTERIOR == 0
    then
        gosub @References_remove
        continue
    end

0D59: get_current_weather_to 1@
if and
    not 1@ == 8 // not weather rain
    not 1@ == 16 // not weather rain 2
then
    if
        856D: not actor 0@ defined
    then
    Peds_Find = 0
    while 0EA7: get_any_char_no_save_recursive Peds_Find progress_to Peds_Find char_to 0@
    4@ = 50.0
    if 82CB:   not actor 0@ bounding_sphere_visible
    then 4@ = 15.0
    end
        080E: get_actor 0@ ped_event_to 1@
        if and
            not 1@ == 9 // ped damaged
            80DF: not actor 0@ driving
            not is_char_script_controlled 0@
            not locate_char_distance_to_char 0@ char $PLAYER_ACTOR radius 4@
            locate_char_distance_to_char 0@ char $PLAYER_ACTOR radius 90.0
        then
            0470: 3@ = actor 0@ current_weapon
            0EFF: get_char_simplest_active_task 0@ id_to 1@ pointer_to 2@
            if and
                3@ == 0 //unarmed
                1@ == 900 //walk
                not Actor.Animation(0@) == "sprint_panic"
                not Actor.Animation(0@) == "woman_runpanic"
                not Actor.Animation(0@) == "idle_chat"
            then
                089F: get_actor 0@ pedtype_to 1@
                if or
                    1@ == 4 //man
                    1@ == 5 //woman
                    1@ == 22 // Prostitute
                then
                    gosub @Ped_skin
                    if
                        Ped_Skin == true
                    then
                        gosub @Load_animation
                        if
                            056D: actor 0@ defined
                        then
                            if
                                not is_char_script_controlled 0@
                            then
                                0E0B: mark_char_as_needed 0@
                                Progress = 0
                                Drink_or_eat = false

                                    if 
                                        02F2:   actor 0@ model == 26 // backpacker
                                    then
                                        Ped_Select = 0
                                        gosub @Camera
                                        gosub @Ped_camera
                                        wait Pause
                                        break
                                    end
                                    
                                    0209: Ped_Select = random_int_in_ranges 1 4
                                    
                                    089F: get_actor 0@ pedtype_to 1@
                                    if or
                                        Ped_Select == 1
                                        1@ == 22 // Prostitute
                                    then
                                        Ped_Select = 1
                                        gosub @Smoke
                                        gosub @Ped_Smoke
                                        wait Pause
                                        break
                                    end
                                    
                                    if
                                        Ped_Select == 2
                                    then
                                        gosub @Eat
                                        if or
                                            2@ == 11
                                            2@ == 12
                                        then gosub @Ped_Eat_STandart
                                        else gosub @Ped_Eat
                                        end
                                        wait Pause
                                        break
                                    end
                                    
                                    if
                                        Ped_Select == 3
                                    then
                                        gosub @Eat
                                        if or
                                            2@ == 11
                                            2@ == 12
                                        then gosub @Ped_Eat_STandart
                                        else gosub @Ped_Eat
                                        end
                                        gosub @Drink
                                        gosub @Ped_Drink
                                        wait Pause
                                        break
                                    end
                                    
                                end
                            end
                        end
                    end
                end
            end
        end
    end
end
end
end


//  ,   

:Camera
0209: 2@ = random_int_in_ranges 1 3
if 2@ == 1
then
    2@ = 98
    2@ *= 4
    read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
else
    2@ = 99
    2@ *= 4
    read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
end
4@ = 0.0
5@ = 0.0
6@ = 0.0
8@ = 1.0
return

:Smoke
2@ = 58
2@ *= 4
read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
4@ = 0.04
5@ = 0.1
6@ = 0.05
8@ = 1.0
return

:Eat
0209: 2@ = random_int_in_ranges 1 13
if
    2@ <= 10
then
    4@ = 0.09
    5@ = 0.05
    6@ = 0.01
    7@ = 90.0
    8@ = 0.6
    9@ = 180.0
    if 2@ == 1
    then
        2@ = 14
        4@ = 0.07
        5@ = 0.025
        6@ = -0.025
        7@ = 0
        8@ = 0.9
        9@ = 90.0
    end
    if 2@ == 2
    then 2@ = 18
    end
    if 2@ == 3
    then 2@ = 19
    end
    if 2@ == 4
    then 2@ = 20
    end
    if 2@ == 5
    then 2@ = 34
    end
    if 2@ == 6
    then 2@ = 45
    end
    if 2@ == 7
    then 2@ = 46
    end
    if 2@ == 8
    then 2@ = 47
    end
    if 2@ == 9
    then 2@ = 48
    end
    if 2@ == 10
    then 2@ = 49
    end
    2@ *= 4
    read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
    2@ = 1
end
if and
    2@ >= 6
    2@ < 11
then
    4@ = 0.07
    5@ = 0.025
    6@ = -0.025
    7@ = 0
    8@ = 0.9
    9@ = 90.0
end

if
    2@ == 11
then
    1@ = 2703
    4@ = 0.07
    5@ = 0.025
    6@ = -0.025
    7@ = 0
    8@ = 0.9
    9@ = 90.0
end
if
    2@ == 12
then
    1@ = 2769
    4@ = 0.09
    5@ = 0.05
    6@ = 0.01
    7@ = 90.0
    8@ = 0.8
    9@ = 180.0
end
return

:drink
0209: 2@ = random_int_in_ranges 1 6
2@ += 39
2@ *= 4
read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
15@ = 0.09
16@ = 0.025
17@ = -0.02
18@ = 0.9
return

//  

:Ped_Smoke
if
    not 21@ == -1
then
    0650: destroy_particle 21@
    21@ = -1
end
0F02:  0@ special_model 1@ bone 24 offset 4@ 5@ 6@ rotation 0 0 0 scale 10@ // bone 34 left hand, 24 right hand, 9 had, 3 tors
set_render_object_scale 10@ 8@ 8@ 8@
0E30: set_render_object_auto_hide 10@ dead 1 weapon 1 car 1
0A1A: actor 0@ perform_walk_animation "WalkSmoke" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 -1 ms // versionC
0669: 21@ = create_attached_particle "EXHALE" on_actor 0@ with_offset 0.0 0.0 0.0 flag 1
0883: attach_particle 21@ to_actor 0@ mode 26
064C: make_particle 21@ visible
0006: TIMERA = 0
0006: TIMERB = 0
return

:Ped_camera
0F02:  0@ special_model 1@ bone 24 offset 4@ 5@ 6@ rotation 0 0 0 scale 10@ // bone 34 left hand, 24 right hand, 9 had, 3 tors
set_render_object_scale 10@ 8@ 8@ 8@
0E30: set_render_object_auto_hide 10@ dead 1 weapon 1 car 1
0006: TIMERA = 0
0006: TIMERB = 0
return

:Ped_Eat
0F02:  0@ special_model 1@ bone 34 offset 4@ 5@ 6@ rotation 0 7@ 9@ scale 10@ // bone 34 left hand, 24 right hand, 9 had, 3 tors
set_render_object_scale 10@ 8@ 8@ 8@
0E30: set_render_object_auto_hide 10@ dead 1 weapon 1 car 1
0006: TIMERA = 0
0006: TIMERB = 0
return

:Ped_Eat_STandart
model.Load(1@)
if
    not model.Available(1@)
then
    repeat
    wait 0
    model.Load(1@)
    until model.Available(1@)
end
038B: load_requested_models
if
    056D:   actor 0@ defined
then
    0E2E: create_render_object_to_char_bone 0@ model 1@ bone 34 offset 4@ 5@ 6@ rotation 0 7@ 9@ store_to 10@
    set_render_object_scale 10@ 8@ 8@ 8@
    0E30: set_render_object_auto_hide 10@ dead 1 weapon 1 car 1
    0006: TIMERA = 0
end
model.Destroy(1@)
return

:Ped_Drink
if
    056D:   actor 0@ defined
then
    0F02:  0@ special_model 1@ bone 24 offset 15@ 16@ 17@ rotation 0 0 0 scale 11@ // bone 34 left hand, 24 right hand, 9 had, 3 tors
    set_render_object_scale 11@ 18@ 18@ 18@
    0E30: set_render_object_auto_hide 11@ dead 1 weapon 1 car 1
end
return

//   


:Ped_20
wait 50
    if
        056D: actor 0@ defined
    then
        0A96: 3@ = ped 0@ struct
        0D4E: 2@ = read_struct 3@ offset 0x470 size 1
        if 08B7:   test 2@ bit 3 //      
        then
            08C3: clear 2@ bit 3
            0E28: write_struct 3@ offset 0x470 size 1 value 2@ //      
            10@ = -1
            11@ = -1
            gosub @PedsMod_Delete_Render
            return
        end
        if and
            not actor.Dead(0@)
            is_char_script_controlled 0@
            locate_char_distance_to_char 0@ char $PLAYER_ACTOR radius 120.0
        then
        
            0EFF: get_char_simplest_active_task 0@ id_to 3@ pointer_to 2@
            if and
                timera > 5000
                3@ == 203
            then
                05DE: AS_actor 0@ walk_around_ped_path
                TIMERA = 0
            end
            
            //  
            if
                Ped_Select == 0
            then
                0EFF: get_char_simplest_active_task 0@ id_to 3@ pointer_to 2@
                if and
                    02CB:   actor 0@ bounding_sphere_visible
                    not 3@ == 401
                    3@ == 900
                    0019:   TIMERA > 20000
                then
                    0A1A: actor 0@ perform_walk_animation "WalkCamera" IFP "PedEventsMod" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                    0006: TIMERA = 0
                end
            end
            
            // 
            if
                Ped_Select == 1
            then
                if
                    0019:   TIMERA > 50
                then
                    0EC0: add_fx_system_particle 21@ coord 0 0 0 vel 0 0 0 size 0.6 brightness 0 rgba 1.0 1.0 1.0 0.5 lastFactor 0.3
                    0006: TIMERA = 0
                end
                0EFF: get_char_simplest_active_task 0@ id_to 3@ pointer_to 2@
                if and
                    02CB:   actor 0@ bounding_sphere_visible
                    0019:   TIMERB > 20000
                    3@ == 900
                    not 3@ == 401
                    not Actor.Animation(0@) == "WalkSmoke"
                then
                    0A1A: actor 0@ perform_walk_animation "WalkSmoke" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                    0006: TIMERB = 0
                    Progress += 1
                end
                if and
                    Progress >= 5
                    0019:   TIMERB > 5000
                then
                    gosub @PedsMod_Delete_Render
                    return
                end
                0D59: get_current_weather_to 2@
                if or
                    2@ == 8 // weather rain
                    2@ == 16 // weather rain 2
                then
                    gosub @PedsMod_Delete_Render
                    return
                end
            end
            
            // 
            if
                Ped_Select == 2
            then
                0EFF: get_char_simplest_active_task 0@ id_to 3@ pointer_to 2@
                if and
                    02CB:   actor 0@ bounding_sphere_visible
                    not 3@ == 401
                    3@ == 900
                    0019:   TIMERA > 20000
                then
                    Progress += 1
                    0A1A: actor 0@ perform_walk_animation "WalkEat" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 10000 ms // versionC
                    0006: TIMERA = 0
                end
                0613: 1@ = actor 0@ animation "WalkEat" time
                if and
                    Progress >= 5
                    1@ >= 0.5
                then
                    gosub @PedsMod_Delete_Render
                    return
                end
            end
            
            
            //   
            if
                Ped_Select == 3
            then
            
                0EFF: get_char_simplest_active_task 0@ id_to 3@ pointer_to 2@
                if and
                    02CB:   actor 0@ bounding_sphere_visible
                    Drink_or_eat == false
                    not 3@ == 401
                    3@ == 900
                    0019:   TIMERA > 15000
                then
                    Drink_or_eat = true
                    Progress += 1
                    0A1A: actor 0@ perform_walk_animation "WalkEat" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 8000 ms // versionC
                    0006: TIMERA = 0
                end
                if and
                    02CB:   actor 0@ bounding_sphere_visible
                    Drink_or_eat == true
                    not 3@ == 401
                    3@ == 900
                    0019:   TIMERA > 10000
                then
                    Drink_or_eat = false
                    Progress += 1
                    0A1A: actor 0@ perform_walk_animation "DRNKBR_PRTL" IFP "GANGS" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                    0006: TIMERA = 0
                end
                if and
                    not Actor.Animation(0@) == "WalkEat"
                    not Actor.Animation(0@) == "DRNKBR_PRTL"
                    Progress >= 6
                then
                    gosub @PedsMod_Delete_Render
                    return
                end
            
            end
            
            080E: get_actor 0@ ped_event_to 1@
            if or
                1@ == 49 // shoot close ped
                0E47: is_char_fighting 0@
                actor.Driving(0@)
                82D8:   not actor 0@ current_weapon == 0
            then
                gosub @PedsMod_Delete_Render
            end
        else
            gosub @PedsMod_Delete_Render
        end
    end
return


//      
:PedsMod_Delete_Render
if
    056D: actor 0@ defined
then
    if
        not locate_char_distance_to_char 0@ char $PLAYER_ACTOR radius 50.0
    then
        if
            0E0A: is_char_script_controlled 0@
        then
            01C2: remove_references_to_actor 0@ // Like turning an actor into a random pedestrian
        end
    else
        if
            Ped_Select == 1
        then
            0650: destroy_particle 21@
            21@ = -1
        end
        if
            0E0A: is_char_script_controlled 0@
        then
            if
                not 10@ <= -1
            then
                0E31: set_render_object_visible 10@ 0
            end
                if
                    Ped_Select == 3
                then
                    if
                        not 11@ <= -1
                    then
                        0E31: set_render_object_visible 11@ 0
                    end
                end
            if
                not actor.Dead(0@)
            then
                if and
                    not Ped_Select == 4
                    Ped_Select >= 1
                then
                    0E97: clear_char_secondary_tasks 0@
                end
            end
            01C2: remove_references_to_actor 0@ // Like turning an actor into a random pedestrian
        end
    end
end
0@ = -1
10@ = -1
11@ = -1
wait Pause
return

//  
:Load_animation
if or
    84EE: not animation "PedEventsMod" loaded
    84EE: not animation "VENDING" loaded
    84EE: not animation "GANGS" loaded
then
    repeat
    wait 0
    04ED: load_animation  "PedEventsMod"
    04ED: load_animation  "VENDING"
    04ED: load_animation  "GANGS"
        if and
            04EE: animation "PedEventsMod" loaded
            04EE: animation "VENDING" loaded
            04EE: animation "GANGS" loaded
        then
            break
        end
    until not player.Defined(0)
end
return


:Ped_skin
Ped_skin = false
if and
    82F2:   not actor 0@ model == 18 // beach visitor
    82F2:   not actor 0@ model == 45 // beach visitor
    82F2:   not actor 0@ model == 138 // beach visitor
    82F2:   not actor 0@ model == 139  // beach visitor
    82F2:   not actor 0@ model == 140 // beach visitor
    82F2:   not actor 0@ model == 154 // beach visitor
    82F2:   not actor 0@ model == 99 // roller
then
    Ped_skin = true
else
    Ped_skin = false
    return
end
if and
    82F2:   not actor 0@ model == 77 // homeless
    82F2:   not actor 0@ model == 78  // homeless
    82F2:   not actor 0@ model == 79 // homeless
    82F2:   not actor 0@ model == 134 // homeless
    82F2:   not actor 0@ model == 135 // homeless
    82F2:   not actor 0@ model == 137 // homeless
    82F2:   not actor 0@ model == 212 // homeless
then
    Ped_skin = true
else
    Ped_skin = false
    return
end
if and
    82F2:   not actor 0@ model == 230 // homeless
    82F2:   not actor 0@ model == 239 // homeless
    82F2:   not actor 0@ model == 92 // roller
    82F2:   not actor 0@ model == 51 // mountain biker
    82F2:   not actor 0@ model == 52 // mountain biker
    82F2:   not actor 0@ model == 16 // worker
    82F2:   not actor 0@ model == 27 // worker
then
    Ped_skin = true
else
    Ped_skin = false
    return
end
if and
    82F2:   not actor 0@ model == 50 // worker mechanik
    82F2:   not actor 0@ model == 260 // worker
    82F2:   not actor 0@ model == 153 // worker
    82F2:   not actor 0@ model == 90 // Jogger
    82F2:   not actor 0@ model == 96 // Jogger
    82F2:   not actor 0@ model == 97 // Lifeguard
    82F2:   not actor 0@ model == 251 // Lifeguard
then
    Ped_skin = true
else
    Ped_skin = false
    return
end
if and
    82F2:   not actor 0@ model == 128 // Farm Inhabitant
    82F2:   not actor 0@ model == 129 // Farm Inhabitant
    82F2:   not actor 0@ model == 130 // Farm Inhabitant
    82F2:   not actor 0@ model == 131 // Farm Inhabitant
    82F2:   not actor 0@ model == 132 // Farm Inhabitant
    82F2:   not actor 0@ model == 133 // Farm Inhabitant
    82F2:   not actor 0@ model == 158 // Farmer
then
    Ped_skin = true
else
    Ped_skin = false
    return
end
if and
    82F2:   not actor 0@ model == 161 // Farmer
    82F2:   not actor 0@ model == 201 // Farmer
    82F2:   not actor 0@ model == 202 // Farmer
    82F2:   not actor 0@ model == 157 // Hillbilly
    82F2:   not actor 0@ model == 159 // Hillbilly
    82F2:   not actor 0@ model == 160 // Hillbilly
    82F2:   not actor 0@ model == 162 // Hillbilly
then
    Ped_skin = true
else
    Ped_skin = false
    return
end
if and
    82F2:   not actor 0@ model == 197 // Hillbilly
    82F2:   not actor 0@ model == 200 // Hillbilly
    82F2:   not actor 0@ model == 31 // Farm-Town inhabitant
    82F2:   not actor 0@ model == 32 // Farm-Town inhabitant
    82F2:   not actor 0@ model == 33 // Farm-Town inhabitant
    82F2:   not actor 0@ model == 34 // Farm-Town inhabitant
    82F2:   not actor 0@ model == 196 // Farm-Town inhabitant
then
    Ped_skin = true
else
    Ped_skin = false
    return
end
if and
    82F2:   not actor 0@ model == 198 // Farm-Town inhabitant
    82F2:   not actor 0@ model == 199 // Farm-Town inhabitant
    82F2:   not actor 0@ model == 33 // Farm-Town inhabitant
    82F2:   not actor 0@ model == 34 // Farm-Town inhabitant
    82F2:   not actor 0@ model == 196 // Farm-Town inhabitant
    82F2:   not actor 0@ model == 71 // security
then
    Ped_skin = true
else
    Ped_skin = false
    return
end
return


//     
:References_remove
    if
        056D:   actor 0@ defined
    then
        01C2: remove_references_to_actor 0@ // Like turning an actor into a random pedestrian
        0@ = -1
        10@ = -1
        11@ = -1
    end
    if
        not 21@ == -1
    then
        0650: destroy_particle 21@
        21@ = -1
    end
return

//      ,   
:Realese_animation
if
    856D: not actor 0@ defined
then
    if and
        04EE: animation "PedEventsMod" loaded
        04EE: animation "VENDING" loaded
        04EE: animation "GANGS" loaded
    then
        04EF: release_animation "PedEventsMod"
        04EF: release_animation "GANGS"
        04EF: release_animation "VENDING"
    end
    0842: 2@ = player $PLAYER_CHAR town_number
    0D59: get_current_weather_to 1@
    if or
        1@ == 8 // not weather rain
        1@ == 16 // not weather rain 2
        not $ACTIVE_INTERIOR == 0
    then
        0A93: terminate_this_custom_script
    end
end
return
